﻿using DotNetCore.CAP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnitOfWorkCore.Domain.Abstractions;
using UnitOfWorkCore.Domain.Events;
using UnitOfWorkCore.Infrastructure.Context;

namespace UnitOfWorkCore.Application.DomainEventHandlers
{
    public class UserCreatedDomainEventHandler : IDomainEventHandler<UserCreatedDomainEvent>
    {
        ICapPublisher _capPublisher;
        AppDbContext _Mddb;
        public UserCreatedDomainEventHandler(ICapPublisher capPublisher, AppDbContext Mddb)
        {
            _Mddb = Mddb;
            _capPublisher = capPublisher;
        }

        public async Task Handle(UserCreatedDomainEvent notification, CancellationToken cancellationToken)
        {
            await _capPublisher.PublishAsync("user.created", notification.user);
        }
    }
}
